home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / Date & Calendars / cal-script.izs < prev    next >
Text File  |  2005-07-20  |  11KB  |  399 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Calender script that shows date and time of today
  4.  
  5. <!/TITLE>
  6.  
  7. <!DESCRIPTION>The below script will display a calender showing the date and time of today...
  8. <!/DESCRIPTION> 
  9.  
  10. <!CATEGORY>Calenders<!/CATEGORY>
  11.  
  12. <!SCRIPT>
  13. <!-- START OF SCRIPT -->
  14. <!-- Simply cut and paste the following into the <body> tags of your page.                -->
  15.  
  16. <script>
  17. /*Copyright 1996 - Tomer and Yehuda Shiran
  18. Feel free to "steal" this code provided that you leave this notice as is.
  19. Additional examples from the book can be found at http://www.geocities.com/SiliconValley/9000/
  20. For more information contact Tomer or Yehuda Shiran <yshiran@iil.intel.com>*/
  21.  
  22. setCal()
  23.  
  24. function getTime() {
  25. // initialize time-related variables with current time settings
  26. var now = new Date()
  27. var hour = now.getHours()
  28. var minute = now.getMinutes()
  29. now = null
  30. var ampm = "" 
  31.  
  32. // validate hour values and set value of ampm
  33. if (hour >= 12) {
  34. hour -= 12
  35. ampm = "PM"
  36. } else
  37. ampm = "AM"
  38. hour = (hour == 0) ? 12 : hour
  39.  
  40. // add zero digit to a one digit minute
  41. if (minute < 10)
  42. minute = "0" + minute // do not parse this number!
  43.  
  44. // return time string
  45. return hour + ":" + minute + " " + ampm
  46. }
  47.  
  48. function leapYear(year) {
  49. if (year % 4 == 0) // basic rule
  50. return true // is leap year
  51. /* else */ // else not needed when statement is "return"
  52. return false // is not leap year
  53. }
  54.  
  55. function getDays(month, year) {
  56. // create array to hold number of days in each month
  57. var ar = new Array(12)
  58. ar[0] = 31 // January
  59. ar[1] = (leapYear(year)) ? 29 : 28 // February
  60. ar[2] = 31 // March
  61. ar[3] = 30 // April
  62. ar[4] = 31 // May
  63. ar[5] = 30 // June
  64. ar[6] = 31 // July
  65. ar[7] = 31 // August
  66. ar[8] = 30 // September
  67. ar[9] = 31 // October
  68. ar[10] = 30 // November
  69. ar[11] = 31 // December
  70.  
  71. // return number of days in the specified month (parameter)
  72. return ar[month]
  73. }
  74.  
  75. function getMonthName(month) {
  76. // create array to hold name of each month
  77. var ar = new Array(12)
  78. ar[0] = "January"
  79. ar[1] = "February"
  80. ar[2] = "March"
  81. ar[3] = "April"
  82. ar[4] = "May"
  83. ar[5] = "June"
  84. ar[6] = "July"
  85. ar[7] = "August"
  86. ar[8] = "September"
  87. ar[9] = "October"
  88. ar[10] = "November"
  89. ar[11] = "December"
  90.  
  91. // return name of specified month (parameter)
  92. return ar[month]
  93. }
  94.  
  95. function setCal() {
  96. // standard time attributes
  97. var now = new Date()
  98. var year = now.getYear()
  99. if (year < 1000)
  100. year+=1900
  101. var month = now.getMonth()
  102. var monthName = getMonthName(month)
  103. var date = now.getDate()
  104. now = null
  105.  
  106. // create instance of first day of month, and extract the day on which it occurs
  107. var firstDayInstance = new Date(year, month, 1)
  108. var firstDay = firstDayInstance.getDay()
  109. firstDayInstance = null
  110.  
  111. // number of days in current month
  112. var days = getDays(month, year)
  113.  
  114. // call function to draw calendar
  115. drawCal(firstDay + 1, days, date, monthName, year)
  116. }
  117.  
  118. function drawCal(firstDay, lastDate, date, monthName, year) {
  119. // constant table settings
  120. var headerHeight = 50 // height of the table's header cell
  121. var border = 2 // 3D height of table's border
  122. var cellspacing = 4 // width of table's border
  123. var headerColor = "midnightblue" // color of table's header
  124. var headerSize = "+3" // size of tables header font
  125. var colWidth = 60 // width of columns in table
  126. var dayCellHeight = 25 // height of cells containing days of the week
  127. var dayColor = "darkblue" // color of font representing week days
  128. var cellHeight = 40 // height of cells representing dates in the calendar
  129. var todayColor = "red" // color specifying today's date in the calendar
  130. var timeColor = "purple" // color of font representing current time
  131.  
  132. // create basic table structure
  133. var text = "" // initialize accumulative variable to empty string
  134. text += '<CENTER>'
  135. text += '<TABLE BORDER=' + border + ' CELLSPACING=' + cellspacing + '>' // table settings
  136. text += '<TH COLSPAN=7 HEIGHT=' + headerHeight + '>' // create table header cell
  137. text += '<FONT COLOR="' + headerColor + '" SIZE=' + headerSize + '>' // set font for table header
  138. text += monthName + ' ' + year 
  139. text += '</FONT>' // close table header's font settings
  140. text += '</TH>' // close header cell
  141.  
  142. // variables to hold constant settings
  143. var openCol = '<TD WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>'
  144. openCol += '<FONT COLOR="' + dayColor + '">'
  145. var closeCol = '</FONT></TD>'
  146.  
  147. // create array of abbreviated day names
  148. var weekDay = new Array(7)
  149. weekDay[0] = "Sun"
  150. weekDay[1] = "Mon"
  151. weekDay[2] = "Tues"
  152. weekDay[3] = "Wed"
  153. weekDay[4] = "Thu"
  154. weekDay[5] = "Fri"
  155. weekDay[6] = "Sat"
  156.  
  157. // create first row of table to set column width and specify week day
  158. text += '<TR ALIGN="center" VALIGN="center">'
  159. for (var dayNum = 0; dayNum < 7; ++dayNum) {
  160. text += openCol + weekDay[dayNum] + closeCol 
  161. }
  162. text += '</TR>'
  163.  
  164. // declaration and initialization of two variables to help with tables
  165. var digit = 1
  166. var curCell = 1
  167.  
  168. for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {
  169. text += '<TR ALIGN="right" VALIGN="top">'
  170. for (var col = 1; col <= 7; ++col) {
  171. if (digit > lastDate)
  172. break
  173. if (curCell < firstDay) {
  174. text += '<TD></TD>';
  175. curCell++
  176. } else {
  177. if (digit == date) { // current cell represent today's date
  178. text += '<TD HEIGHT=' + cellHeight + '>'
  179. text += '<FONT COLOR="' + todayColor + '">'
  180. text += digit
  181. text += '</FONT><BR>'
  182. text += '<FONT COLOR="' + timeColor + '" SIZE=2>'
  183. text += '<CENTER>' + getTime() + '</CENTER>'
  184. text += '</FONT>'
  185. text += '</TD>'
  186. } else
  187. text += '<TD HEIGHT=' + cellHeight + '>' + digit + '</TD>'
  188. digit++
  189. }
  190. }
  191. text += '</TR>'
  192. }
  193.  
  194. // close all basic table tags
  195. text += '</TABLE>'
  196. text += '</CENTER>'
  197.  
  198. // print accumulative HTML string
  199. document.write(text) 
  200. }
  201. </script>
  202.  
  203. <!-- END OF SCRIPT -->
  204. <!/SCRIPT>
  205.  
  206. <!PREVIEW>
  207. <!-- START OF SCRIPT -->
  208. <!-- Simply cut and paste the following into the <body> tags of your page.                -->
  209.  
  210. <script>
  211. /*Copyright 1996 - Tomer and Yehuda Shiran
  212. Feel free to "steal" this code provided that you leave this notice as is.
  213. Additional examples from the book can be found at http://www.geocities.com/SiliconValley/9000/
  214. For more information contact Tomer or Yehuda Shiran <yshiran@iil.intel.com>*/
  215.  
  216. setCal()
  217.  
  218. function getTime() {
  219. // initialize time-related variables with current time settings
  220. var now = new Date()
  221. var hour = now.getHours()
  222. var minute = now.getMinutes()
  223. now = null
  224. var ampm = "" 
  225.  
  226. // validate hour values and set value of ampm
  227. if (hour >= 12) {
  228. hour -= 12
  229. ampm = "PM"
  230. } else
  231. ampm = "AM"
  232. hour = (hour == 0) ? 12 : hour
  233.  
  234. // add zero digit to a one digit minute
  235. if (minute < 10)
  236. minute = "0" + minute // do not parse this number!
  237.  
  238. // return time string
  239. return hour + ":" + minute + " " + ampm
  240. }
  241.  
  242. function leapYear(year) {
  243. if (year % 4 == 0) // basic rule
  244. return true // is leap year
  245. /* else */ // else not needed when statement is "return"
  246. return false // is not leap year
  247. }
  248.  
  249. function getDays(month, year) {
  250. // create array to hold number of days in each month
  251. var ar = new Array(12)
  252. ar[0] = 31 // January
  253. ar[1] = (leapYear(year)) ? 29 : 28 // February
  254. ar[2] = 31 // March
  255. ar[3] = 30 // April
  256. ar[4] = 31 // May
  257. ar[5] = 30 // June
  258. ar[6] = 31 // July
  259. ar[7] = 31 // August
  260. ar[8] = 30 // September
  261. ar[9] = 31 // October
  262. ar[10] = 30 // November
  263. ar[11] = 31 // December
  264.  
  265. // return number of days in the specified month (parameter)
  266. return ar[month]
  267. }
  268.  
  269. function getMonthName(month) {
  270. // create array to hold name of each month
  271. var ar = new Array(12)
  272. ar[0] = "January"
  273. ar[1] = "February"
  274. ar[2] = "March"
  275. ar[3] = "April"
  276. ar[4] = "May"
  277. ar[5] = "June"
  278. ar[6] = "July"
  279. ar[7] = "August"
  280. ar[8] = "September"
  281. ar[9] = "October"
  282. ar[10] = "November"
  283. ar[11] = "December"
  284.  
  285. // return name of specified month (parameter)
  286. return ar[month]
  287. }
  288.  
  289. function setCal() {
  290. // standard time attributes
  291. var now = new Date()
  292. var year = now.getYear()
  293. if (year < 1000)
  294. year+=1900
  295. var month = now.getMonth()
  296. var monthName = getMonthName(month)
  297. var date = now.getDate()
  298. now = null
  299.  
  300. // create instance of first day of month, and extract the day on which it occurs
  301. var firstDayInstance = new Date(year, month, 1)
  302. var firstDay = firstDayInstance.getDay()
  303. firstDayInstance = null
  304.  
  305. // number of days in current month
  306. var days = getDays(month, year)
  307.  
  308. // call function to draw calendar
  309. drawCal(firstDay + 1, days, date, monthName, year)
  310. }
  311.  
  312. function drawCal(firstDay, lastDate, date, monthName, year) {
  313. // constant table settings
  314. var headerHeight = 50 // height of the table's header cell
  315. var border = 2 // 3D height of table's border
  316. var cellspacing = 4 // width of table's border
  317. var headerColor = "midnightblue" // color of table's header
  318. var headerSize = "+3" // size of tables header font
  319. var colWidth = 60 // width of columns in table
  320. var dayCellHeight = 25 // height of cells containing days of the week
  321. var dayColor = "darkblue" // color of font representing week days
  322. var cellHeight = 40 // height of cells representing dates in the calendar
  323. var todayColor = "red" // color specifying today's date in the calendar
  324. var timeColor = "purple" // color of font representing current time
  325.  
  326. // create basic table structure
  327. var text = "" // initialize accumulative variable to empty string
  328. text += '<CENTER>'
  329. text += '<TABLE BORDER=' + border + ' CELLSPACING=' + cellspacing + '>' // table settings
  330. text += '<TH COLSPAN=7 HEIGHT=' + headerHeight + '>' // create table header cell
  331. text += '<FONT COLOR="' + headerColor + '" SIZE=' + headerSize + '>' // set font for table header
  332. text += monthName + ' ' + year 
  333. text += '</FONT>' // close table header's font settings
  334. text += '</TH>' // close header cell
  335.  
  336. // variables to hold constant settings
  337. var openCol = '<TD WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>'
  338. openCol += '<FONT COLOR="' + dayColor + '">'
  339. var closeCol = '</FONT></TD>'
  340.  
  341. // create array of abbreviated day names
  342. var weekDay = new Array(7)
  343. weekDay[0] = "Sun"
  344. weekDay[1] = "Mon"
  345. weekDay[2] = "Tues"
  346. weekDay[3] = "Wed"
  347. weekDay[4] = "Thu"
  348. weekDay[5] = "Fri"
  349. weekDay[6] = "Sat"
  350.  
  351. // create first row of table to set column width and specify week day
  352. text += '<TR ALIGN="center" VALIGN="center">'
  353. for (var dayNum = 0; dayNum < 7; ++dayNum) {
  354. text += openCol + weekDay[dayNum] + closeCol 
  355. }
  356. text += '</TR>'
  357.  
  358. // declaration and initialization of two variables to help with tables
  359. var digit = 1
  360. var curCell = 1
  361.  
  362. for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {
  363. text += '<TR ALIGN="right" VALIGN="top">'
  364. for (var col = 1; col <= 7; ++col) {
  365. if (digit > lastDate)
  366. break
  367. if (curCell < firstDay) {
  368. text += '<TD></TD>';
  369. curCell++
  370. } else {
  371. if (digit == date) { // current cell represent today's date
  372. text += '<TD HEIGHT=' + cellHeight + '>'
  373. text += '<FONT COLOR="' + todayColor + '">'
  374. text += digit
  375. text += '</FONT><BR>'
  376. text += '<FONT COLOR="' + timeColor + '" SIZE=2>'
  377. text += '<CENTER>' + getTime() + '</CENTER>'
  378. text += '</FONT>'
  379. text += '</TD>'
  380. } else
  381. text += '<TD HEIGHT=' + cellHeight + '>' + digit + '</TD>'
  382. digit++
  383. }
  384. }
  385. text += '</TR>'
  386. }
  387.  
  388. // close all basic table tags
  389. text += '</TABLE>'
  390. text += '</CENTER>'
  391.  
  392. // print accumulative HTML string
  393. document.write(text) 
  394. }
  395. </script>
  396. <!-- END OF SCRIPT -->
  397. <!/PREVIEW>
  398.  
  399. <!RELATED>NONE<!/RELATED>